<template>
	<view class="content">
		<view v-if="show==1">
			<view class="top" style="margin-bottom: 1.5vh;">
				<text class="title">人员信息</text>
				<view class="ren">
					<view class="ziren">
						<text class="zititle">工单信息</text>
						<view class="rendata">
							<view class="VIN" style="margin-top: 1vh;"><span>工单名称:</span><span style="margin-left:1vw;">{{data.znddWorkOrder.workOrderName}}</span>
							</view>
							<view class="VIN" style="margin-top: 1vh;"><span>预计开始时间:</span><span style="margin-left:1vw;">{{data.znddWorkOrder.exStartTime}}</span>
							</view>
							<view class="VIN" style="margin-top: 1vh;"><span>预计结束时间:</span><span style="margin-left:1vw;">{{data.znddWorkOrder.exEndTime}}</span>
							</view>
						</view>
					</view>
					<view class="ziren">
						<text class="zititle">初始人员</text>
						<view class="rendata">
							<!-- <span class="rendatazi">张三</span> <span class="rendatazi">李四</span><span
								class="rendatazi">王二</span><span class="rendatazi">麻子</span> -->
							<span class="rendatazi" v-for="(item, index) in data.initialEmployeeList"
								:key="index">{{item.employeeName}}</span>
						</view>
					</view>
					<view class="ziren">
						<text class="zititle">备用人员</text>
						<view class="rendata">
						<!-- 	<span class="rendatazi">张三</span> <span class="rendatazi">李四</span><span
								class="rendatazi">王二</span><span class="rendatazi">麻子</span> -->
							<span class="rendatazi" v-for="(item, index) in data.increasedEmployeeList" :key="index">{{item.employeeName}}</span>
						</view>
					</view>
				</view>
			</view>
			<view class="bottom">
				<text class="title">焊缝信息</text>
				<view class="shudu">
					<mescroll-uni ref="mescrollRef" htmlNodata="没有更多数据" @init="mescrollInit"
						hardwareClass="mescroll-hardware" @down="refreshChange" @up="loadChange" :down="down" :up="up"
						:fixed="true" :top="top">
						<view class="item" v-for="(item, index) in data.znddActionDeviceVoList" :key="index">
							<view style="margin-top: 1vh;" class="zuo">
								<view class="name"><span>焊缝编号:</span><span style="margin-left:1vw;">{{item.weldNo}}</span></view>
								<view class="tel"><span>焊缝长度:</span><span style="margin-left:1vw;">{{item.weldLength}} mm</span></view>
							</view>
							<view style="margin-top:1vh;" class="you">
								<view class="VIN"><span>起始点编号:</span><span style="margin-left:1vw;">{{item.startNo}}</span>
								</view>
								<view class="VIN"><span>结束点编号:</span><span style="margin-left:1vw;">{{item.endNo}}</span>
								</view>
							</view>
						</view>
					</mescroll-uni>
				</view>
			</view>
			<view  v-if="data.znddWorkOrder.doWorkerStatus=='1'" class="float-button">
				<view  @click="work(data.znddWorkOrder.id)">下工</view>
			</view>
		</view>
		<view class="wrap" v-if="show==0">
			<view class="title" style="margin-top: 10px;font-size: 20px;color: aqua;">备料信息</view>
			<view class="shu">
				<mescroll-uni ref="mescrollRef" htmlNodata="没有更多数据" @init="mescrollInit"
					hardwareClass="mescroll-hardware" @down="refreshChange" @up="loadChange" :down="down" :up="up"
					:fixed="true" :top="80">
					<view class="item" v-for="(item, index) in data" :key="index">
						<view class="zou">
							<view class="top" style="margin-top: 1vh;">
								<view class="name"><span>工单名称:</span> <span style="margin-left:1vw;">{{item.orderName}}</span></view>
							</view>
							<view style="margin-top: 1vh;" class="zhong">
								<view class="tel"><span>备料状态:</span> <span style="margin-left:1vw;">{{item.stockState == "0"?"已开始":"已完成"}}</span></view>
							</view>
							<view style="margin-top: 1vh;" class="bottom">
								<view class="VIN"><span>备料开始时间:</span><span style="margin-left:1vw;">{{item.stockBeginTime}}</span>
								</view>
								<view class="VIN"><span>备料结束时间:</span><span style="margin-left:1vw;">{{item.stockEndTime}}</span>
								</view>
							</view>
						</view>
						<view class="you" v-if="item.remark=='0'">
							<view class="bxy" @click.native.stop="bl(item.id)">备料完成</view>
						</view>
						<view class="you" v-if="item.remark=='1'">
							<view class="bxy" style="color:red;">拉动中</view>
						</view>
					</view>
				</mescroll-uni>
			</view>
		</view>
		<view class="wrap" v-if="show==2">没有数据</view>
	</view>
</template>

<script>
	import MescrollMixin from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js';
	import MescrollUni from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-uni.vue";
	import {
		getProcessdata,workchuli
	} from '@/api/index'
	export default {
		data() {
			return {
				show: 2,
				top:580,
				mescroll: null,
				up: {
					auto: false, //默认开始不执行上拉
					htmlNodata: '无数据的布局'
				},
				down: {
					auto: false //默认开始不执行下拉	
				},
				loading: true,
				currentPage: 0,
				pageSize: 10,
				timer: null,
				indexList: [],
				data: {
					
				}
			}
		},
		mixins: [MescrollMixin], //引入mescroll内置方法
		components: {
			MescrollUni
		},
		beforeCreate() {
			if (this.timer) {
				clearInterval(this.timer); // 清除定时器
				this.timer = null; // 清除引用，防止内存泄漏
			}
		},
		beforeDestroy() {
		    // 在这里执行销毁前的操作，例如清除定时器、取消事件监听等
		   if (this.timer) {
		   	clearInterval(this.timer); // 清除定时器
		   	this.timer = null; // 清除引用，防止内存泄漏
		   }
		},
		destroyed() {
		    // 在这里执行销毁后的操作，例如清理资源、记录日志等
			if (this.timer) {
				clearInterval(this.timer); // 清除定时器
				this.timer = null; // 清除引用，防止内存泄漏
			}
		},
		onShow() {
			this.getData();
			this.initdata();
		},
		onHide(){
			if (this.timer) {
				clearInterval(this.timer); // 清除定时器
				this.timer = null; // 清除引用，防止内存泄漏
			}
		},
		methods: {
			bl(id) {
			  var data={
				  id:id,
				  type:"0"
			  };
			  workchuli(data).then(response => {
				console.log(response);
				this.$modal.msgSuccess("备料成功")
			  })
			},
			work(id) {
				var data={
					id:id,
					type:"1"			  
				};
				workchuli(data).then(response => {
					console.log(response);
					this.$modal.msgSuccess("下工成功")
				})
			},
			refreshChange(data = {}) {
				console.log('refresh')
				this.mescroll.removeEmpty(); //移除空布局，主要是第一次无值，第二次有值
				this.mescroll.showUpScroll(); //显示上拉加载，主要用于标签1加载完END，切换标签2时默认替换END(有切换标签时调用)
				this.siteList = [];
				this.hasNext = true; //初始化有值
				this.currentPage = 0;
				this.getData();
			},
			loadChange() {
				console.log('load')
				this.getData();
			},
			getData() {
				
				this.currentPage = this.currentPage + 1;
				getProcessdata().then(response => {
					
					if (response.data.data !== null && response.data.data !== undefined && Object.keys(response.data.data).length > 0) {
					    // 对象不为空
						this.show=response.data.type;
						this.data=response.data.data;
						console.log(response.data.data)
						this.mescroll.endSuccess(1, this
							.hasNext)
						if(this.show==1){
							if(this.data.increasedEmployeeList!=null && this.data.increasedEmployeeList.length>0){
								this.top=620;
							}
						}
					}else{
						this.show=2;
						console.log("-----------------------")
					}
					// for (let i = 0; i < 30; i++) {
					// 	this.indexList.push({
					// 		url: this.urls[uni.$u.random(0, this.urls.length - 1)],
					// 	});
					// }
				})

			},
			initdata() {
				this.timer = window.setInterval(() => {
					this.getData();
				}, 2000);
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f5f5f5;
	}

	.content {
		height: 80vh;
	}

	.wrap {
		height: 80vh;
		position: relative;
		display: flex;
	}

	

	.float-button {
		position: fixed;
		top: 50%;
		right: 5px;
		z-index: 99;
		background-color: #007aff;
		color: white;
		border: none;
		border-radius: 50%;
		padding: 10px;
		cursor: pointer;
		font-size: 20px;
	}

	.top {
		width: 100vw;
		margin-top: 1vh;

		.title {
			height: 20%;
			margin-left: 10px;
			font-weight: bold;
			font-size: 20px;

		}
		.ren {
			height: 80%;
			.ziren {
				margin-top: 1vh;
				height: 50%;
				.zititle {
					height: 20%;
					margin-left: 20px;
					justify-content: center;
					color: #7ab0cd;
					font-weight: bold;
					font-size: 15px;
				}
				.rendata {
					width: 100%;
					margin-left: 20px;
					margin-top: 1vh;
					.rendatazi {
						margin-left: 20px;
						font-size: 15px;
						color: #1cbbb4;
						font-weight: bold;
						padding: 20rpx 20rpx;
						border-radius: 3vw;
						background-color: #ffffff;
						border-style: solid;
						border-color: whitesmoke;
						border-width: 1vw;
					}
				}
			}

		}
	}

	.bottom {
		width: 100vw;
		.title {
			margin-left: 10px;
			justify-content: center;
			height: 20%;
			font-weight: bold;
			font-size: 20px;
		}
	}

	.shudu {
		height: 80%;
		.item {
			position: relative;
			display: flex;
			padding: 40rpx 20rpx;
			border-radius: 3vw;
			background-color: #ffffff;
			border-style: solid;
			border-color: whitesmoke;
			border-width: 1vw;
			display: flex;
			justify-content: space-around;
			.zuo {
				display: list-item;
				flex: 1;
			}
			.you {
				display: list-item;
				flex: 1;
			}
		
		}
	}

	.shu {
		height: 80%;
		.item {
			position: relative;
			display: flex;
			padding: 40rpx 20rpx;
			border-radius: 3vw;
			background-color: #ffffff;
			border-style: solid;
			border-color: whitesmoke;
			border-width: 1vw;
			.zuo {
				width: 80wv;
				display: list-item;
				.top {
					display: flex;
					font-weight: bold;
					font-size: 34rpx;
					padding: 0rpx 0rpx 5rpx 0rpx;
				}
		
				.zhong {
					display: flex;
					font-weight: bold;
					font-size: 34rpx;
					padding: 0rpx 0rpx 5rpx 0rpx;
				}
		
				.bottom {
					padding: 0rpx 0rpx 5rpx 0rpx;
					display: flex;
					margin-top: 20rpx;
					font-size: 28rpx;
					color: #999999;
				}
			}
		
			.you {
				display: flex;
				position: absolute;
				right: 0vw;
				width: 20vw;
				height: 100%;
				text-align: center;
				align-items: center;
		
				.bxy {
					position: absolute;
					display: flex;
					width: 20vw;
					height: 5vh;
					justify-content: center;
					text-align: center;
					background-color: #ffffff;
					font-weight: normal;
					font-size: 4vw;
					color: #0069ff;
					border: none;
				}
			}
		
		}
	}
</style>